package logic

import (
	"context"
	"order_srv/model/mysql"

	"order_srv/internal/svc"
	"order_srv/order"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateOrderLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateOrderLogic {
	return &CreateOrderLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CreateOrderLogic) CreateOrder(in *order.CreateOrderRequest) (*order.CreateOrderResponse, error) {
	// todo: 新增订单

	o := mysql.OrderZye3{
		UserId:  in.UserId,
		GoodsSn: in.GoodsSn,
		Amount:  in.Amount,
		Payment: int8(in.Payment),
		Status:  int8(in.Status),
	}

	err := o.CreateOrder()
	if err != nil {
		logx.Error("新增订单失败", err)
		return nil, err
	}

	return &order.CreateOrderResponse{OrderId: int64(o.ID)}, nil
}
